19. Data Exploration
Data Exploration
For the exercises throughout the rest of this lesson, we'll use a relatively small labeled dataset to try out feature extraction and training a classifier. Before we get on to extracting HOG features and training a classifier, let's explore the dataset a bit. This dataset is a subset of the data you'll be starting with for the project.
There's no need to download anything at this point, but if you want to, you can download this subset of images for vehicles and non-vehicles , or if you prefer you can directly grab the larger project dataset for vehicles and non-vehicles .
These datasets are comprised of images taken from the GTI vehicle image database , the KITTI vision benchmark suite , and examples extracted from the project video itself. In this exercise, you can explore the data to see what you're working with.
You are also welcome and encouraged to explore the recently released
Udacity labeled dataset
. Each of the Udacity datasets comes with a
labels.csv
file that gives bounding box corners for each object labeled.
Here, I've provided you with the code to extract the car/not-car image filenames into two lists. Write a function that takes in these two lists and returns a dictionary with the keys "n_cars", "n_notcars", "image_shape", and "data_type", like this:
# Define a function to return some characteristics of the dataset
def data_look(car_list, notcar_list):
data_dict = {}
# Define a key in data_dict "n_cars" and store the number of car images
# Define a key "n_notcars" and store the number of notcar images
# Read in a test image, either car or notcar
# Define a key "image_shape" and store the test image shape 3-tuple
# Define a key "data_type" and store the data type of the test image.
# Return data_dict
return data_dict
car_notcar
Start Quiz:
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
import cv2
import glob
#from skimage.feature import hog
#from skimage import color, exposure
# images are divided up into vehicles and non-vehicles
images = glob.glob('*.jpeg')
cars = []
notcars = []
for image in images:
if 'image' in image or 'extra' in image:
notcars.append(image)
else:
cars.append(image)
# Define a function to return some characteristics of the dataset
def data_look(car_list, notcar_list):
data_dict = {}
# Define a key in data_dict "n_cars" and store the number of car images
data_dict["n_cars"] = 0
# Define a key "n_notcars" and store the number of notcar images
data_dict["n_notcars"] = 0
# Read in a test image, either car or notcar
# Define a key "image_shape" and store the test image shape 3-tuple
data_dict["image_shape"] = (0, 0, 0)
# Define a key "data_type" and store the data type of the test image.
data_dict["data_type"] = None
# Return data_dict
return data_dict
data_info = data_look(cars, notcars)
print('Your function returned a count of',
data_info["n_cars"], ' cars and',
data_info["n_notcars"], ' non-cars')
print('of size: ',data_info["image_shape"], ' and data type:',
data_info["data_type"])
# Just for fun choose random car / not-car indices and plot example images
car_ind = np.random.randint(0, len(cars))
notcar_ind = np.random.randint(0, len(notcars))
# Read in car / not-car images
car_image = mpimg.imread(cars[car_ind])
notcar_image = mpimg.imread(notcars[notcar_ind])
# Plot the examples
fig = plt.figure()
plt.subplot(121)
plt.imshow(car_image)
plt.title('Example Car Image')
plt.subplot(122)
plt.imshow(notcar_image)
plt.title('Example Not-car Image')
# Define a function to return some characteristics of the dataset
def data_look(car_list, notcar_list):
data_dict = {}
# Define a key in data_dict "n_cars" and store the number of car images
data_dict["n_cars"] = len(car_list)
# Define a key "n_notcars" and store the number of notcar images
data_dict["n_notcars"] = len(notcar_list)
# Read in a test image, either car or notcar
example_img = mpimg.imread(car_list[0])
# Define a key "image_shape" and store the test image shape 3-tuple
data_dict["image_shape"] = example_img.shape
# Define a key "data_type" and store the data type of the test image.
data_dict["data_type"] = example_img.dtype
# Return data_dict
return data_dict